import React from "react";
// 导入store
import store from "../../store";
// 导入action
import { sendAction } from "../../action";

export default class Home extends React.Component {

    handleClick = () => {
        // 调用action 函数 ，得到action对象
        const action = sendAction()
        // 发送一个action，利用store
        store.dispatch(action) // 用dispatch来发送action
    }
    // 当组件一加载完毕的时候，来监听
    componentDidMount() {
        store.subscribe(() => {
            console.log("subscribe", store.getState());
            this.setState({})
        })
    }
    render() {
        return (
            <>
                <button onClick={this.handleClick}>点击我，发送一个action</button>
                <div>{store.getState().value}</div>
            </>

        )
    }
}
